#!/bin/bash

FILE_NAME=dtrd-boot.jar

function package() {
  mvn clean compile install -P$1
}

function goDest() {
  echo '============================================='
  echo ''
  echo '进入打包目录 '
  cd system/target
  ls .
}

function upload() {
  echo '============================================='
  echo ''
  echo "准备上传 ,上传地址  $1"
  scp *.jar root@$1:/docker/java/$FILE_NAME

  ssh root@$1
}

# choice run options
while :; do
  echo
  echo 'Please select the run cmd:'
  echo -e "\t${CMSG}1${CEND}. 打包 OMS测试环境"
  echo -e "\t${CMSG}2${CEND}. 打包 OMS生产环境"
  read -e -p "Please input a number:(Default 1 press Enter) " cmd
  cmd=${cmd:-1}
  if [[ ! ${cmd} =~ ^[1-2]$ ]]; then
    echo "${CWARNING}input error! Please only input number 1~4${CEND}"
  else
    case $cmd in
    1)
      echo "准备打包OMS测试环境"
      echo ''
      package 'dev'
      goDest
      upload '47.106.78.19'
      ;;
    2)
      echo "准备打包OMS生成环境"
      echo ''
      package 'prod'
      goDest
      upload '8.134.137.226'
      ;;
    esac

    break
  fi
done
